//
//  Level.h
//  NinjaTurtle
//
//  Created by Nguyen Tri Chung on 1/27/15.
//
//

#ifndef __NinjaTurtle__Level__
#define __NinjaTurtle__Level__

#include <stdio.h>
#include "cocos2d.h"
#include "../global/global.h"
#include "Turtle.h"
#include "CommonObj.h"
#include "GameModel.h"
#include "EnemyObj.h"
#include "StaticObj.h"

USING_NS_CC;

class Level : public Ref {
    CC_SYNTHESIZE_READONLY(int, level, Level);
    CC_SYNTHESIZE_READONLY(TMXTiledMap*, mapInfo, MapInfo);
    CC_SYNTHESIZE_READONLY(Turtle*, turtle, Turtle);
    CC_SYNTHESIZE_READONLY(Size, mapSize, MapSize);
    CC_SYNTHESIZE_READONLY(Size, tileSize, TileSize);
    CC_SYNTHESIZE_READONLY(Point, viewPoint, ViewPoint);
    CC_SYNTHESIZE(float, accelWorld, AccelWorld);
    
    CC_SYNTHESIZE_READONLY(Vector<Obj*>*, lands, Lands);
    CC_SYNTHESIZE_READONLY(Vector<StaticObj*>*, pushObjects, PushObjects);
    CC_SYNTHESIZE_READONLY(Vector<StaticObj*>*, treeObjects, TreeObjects);
    CC_SYNTHESIZE_READONLY(Vector<StaticObj*>*, teleportObjects, TeleportObjects);
    CC_SYNTHESIZE_READONLY(Vector<Obj*>*, finishObjects, FinishObjects);
    CC_SYNTHESIZE_READONLY(Vector<CommonObj*>*, hintObjects, HintObjects);
    CC_SYNTHESIZE_READONLY(Vector<CommonObj*>*, trapObjects, TrapObjects);
    CC_SYNTHESIZE_READONLY(Vector<EnemyObj*>*, enemyObjects, EnemyObjects);
    CC_SYNTHESIZE_READONLY(Vector<CommonObj*>*, bulletObjects, BulletObjects);
protected:
    CommonObj* interactedHint;
public:
    Level(int level);
    virtual ~Level();
    void loadMap();
    void update(float dt);
    void updateViewPoint();
    Point getViewPoint(const Point& position);
    void updateProperties(string propertyText, Obj* obj);
    
    void updateEnemyCrusher(EnemyObj* enemy, float dt);
    void updateEnemyRunner(EnemyObj* enemy, float dt);
    void updateEnemyMachine(EnemyObj* enemy, float dt);
    void updateBullet(float dt);
    void updateTurtle(float dt);
    void updateObjectPushing(float dt);
    void updateObjectTree(float dt);
    void updateObjectTeleport(float dt);
    bool checkEquip();
    void turtleFire();
    bool canSee(RectBody* body);
    bool canSee2(RectBody* body, const Point& viewPoint);
};

#endif /* defined(__NinjaTurtle__Level__) */
